/**
 * WebSocketHandler.java created by zhangzhidong 
 * at 下午2:16:09 2016年8月2日
 */
package websocket;

import org.springframework.util.Assert;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

import controllers.wechatlab.WechatController;

public class WechatModelWebSocketHandler extends TextWebSocketHandler {
	WechatController wc;

	// Map<Object,WebSocketSession> sessions = new
	// java.util.concurrent.ConcurrentHashMap<Object, WebSocketSession>();
	@Override
	public void afterConnectionEstablished(WebSocketSession session) throws Exception {
		super.afterConnectionEstablished(session);
		wc.establishWebSocket(session);

	}
	public void afterConnectionClosed(WebSocketSession session, org.springframework.web.socket.CloseStatus status)
			throws Exception {
		super.afterConnectionClosed(session, status);
		wc.closeWebSocket(session, status);
	};
	@Override
	protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
		super.handleTextMessage(session, message);

		wc.receiveMessageFromWebSocket(session, message);
	}
	public final void setController(WechatController wc) {
		Assert.isNull(this.wc);
		this.wc = wc;
	}
}
